package com.atguigu.yygh.user.controller;

import com.atguigu.yygh.model.user.UserInfo;
import com.atguigu.yygh.result.Result;
import com.atguigu.yygh.user.service.UserInfoService;
import com.atguigu.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zr
 * @date 2021/12/19 20:45
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/admin/user")
@Slf4j
public class UserController {
    @Resource
    private UserInfoService userInfoService;

    @ApiOperation("条件查询带分页")
    @GetMapping("{page}/{limit}")
    public Result listUsers(@PathVariable long limit,
                            @PathVariable long page,
                            UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> userInfoPage = new Page<>(page, limit);
        userInfoService.selectPage(userInfoPage, userInfoQueryVo);
        return Result.ok(userInfoPage);
    }

    @ApiOperation("用户锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result lockUser(@PathVariable Integer status, @PathVariable long userId) {
        boolean flag = userInfoService.lockUser(status, userId);
        return flag ? Result.ok() : Result.fail();
    }

    @ApiOperation("用户详情")
    @GetMapping("show/{userId}")
    public Result showUserDetail(@PathVariable long userId) {
        Map<String, Object> resultMap = userInfoService.showUserDetail(userId);
        return Result.ok(resultMap);
    }

    @ApiOperation("认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approveUser(@PathVariable Integer authStatus, @PathVariable long userId) {
        boolean flag = userInfoService.approveUser(authStatus, userId);
        return flag ? Result.ok() : Result.fail();
    }
}
